<?php

/**
 * Class for controlling the livechat configuration
 *
 * @access 	public
 * @author      Rob
 * @copyright	ResMania 2009-present all rights reserved.
 * @version	1.0
 * @link	http://docs.resmania.com/index.php/LiveChat_Module
 * @since  	09-2010
 */
class RM_LiveChatConfig extends RM_Model_Flexible {

    protected $_name = 'rm_livechat_config';

    /**
     * update the operator status
     *
     * @todo the operator ID is hard coded when groups are added to resmania we
     * will need to look at these and add a livechat operator and update this id
     * when the admin is logged in.
     * @param  array   $operatorInfo   contains the data to update
     * @return object  dataset
     */
    public function updateOperatorStatus($operatorInfo) {

        $where = "id='1'";

        return parent::update($operatorInfo, $where);
    }

    /**
     * gets the operator status, used for the online/offline tracking
     * oparators that have not updated the heartbeat in 5 minutes will not be returned
     *
     * @todo need to add a check on this for session if the admin has closed the
     * browser the status is still online as this is stored in the db only
     * @return object  dataset
     */
    public function getStatus(){

        $fiveMinutesAgo = (int)Date("U") - 300;

        $sql = "
            SELECT
                *
            FROM
                ".$this->_name."
            WHERE
                id='1' AND operator_heartbeat > ".$fiveMinutesAgo;

        return $this->_getBySQL($sql);
    }

    /**
     * gets the operator name
     *
     * @todo the operator ID is hard coded we will need to change this to supprt
     * differnt operators later when the resmania management groups are added
     * @return object  dataset
     */
    public function getOperator() {
        $sql = "
            SELECT
                operator_name
            FROM
                " . $this->_name . "
            WHERE
                id='1'
            ";

        return $this->_getBySQL($sql);
    }

    /**
     * gets the config
     *
     * @todo the operator ID is hard coded we will need to change this to supprt
     * differnt operators later when the resmania management groups are added
     * @return object  dataset
     */
    public function getConfig() {
        $sql = "
            SELECT
                *
            FROM
                " . $this->_name . "
            WHERE
                id='1'
            ";

        return $this->_getBySQL($sql);
    }

}
?>